﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>排产反馈管理页面</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
</head>
<body>
    <div class="panelSection">
        <div class="easyui-panel " title="查询区域" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0px 3px 3px">
                <div style="float: left">
                    <div class="divLabel" style="margin-bottom: 5px">
                        订单号：</div>
                    <input id="txtOrderNum" class="easyui-textbox" style="width: 120px; height: 20px" />
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px">
                        批次号：</div>
                    <input id="txtContainerNum" class="easyui-textbox" style="width: 120px; height: 20px" />
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px">
                        件号：</div>
                    <input id="txtProductNum" class="easyui-textbox" style="width: 120px; height: 20px" />
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px">
                        排产开始时间：</div>
                    <input id="txtPlanStartTime" class="easyui-datebox" style="width: 120px; height: 20px" />
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px">
                        排产结束时间：</div>
                    <input id="txtPlanEndTime" class="easyui-datebox" style="width: 120px; height: 20px" />
                </div>
                <div style="float: left; margin-left: 10px">
                    <button id="btnSearch" class="easyui-linkbutton" data-options="" style="margin-top: 16px;
                        width: 50px;">
                        查询</button>
                    <button id="btnReset" class="easyui-linkbutton" data-options="" style="margin-top: 16px;
                        width: 50px;">
                        重置</button>
                </div>
                <div style="clear: both">
                </div>
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="查询结果" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="background: #fff; margin: 3px 0px 3px 3px">
                <div style="width: 1100px;">
                    <table id="gdApsPlanInfo" class="easyui-datagrid" style="width: 100%; height: 300px;"
                        data-options="rownumbers:true">
                    </table>
                    <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                    buttons:[{
                            iconCls:'',
                            text:'Go',
                            group:'paging-tail-btns',
                            id:'pageGo'
                    }]  
                ">
                    </div>
                </div>
                <div style="clear: both">
                </div>
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="工序排产详细信息" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0 0 3px">
                <div style="float: left">
                    <div style="float: left">
                        <div class="divLabel" style="margin-bottom: 5px;">
                            工区：</div>
                        <select id="ddlWorkcenter" class="easyui-combobox" data-options="width:120,height:20 ">
                        </select>
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px;">
                            班组：</div>
                        <select id="ddlTeam" class="easyui-combobox" data-options="width:120,height:20, panelHeight:'auto' ">
                        </select>
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px;">
                            设备：</div>
                        <select id="ddlResource" class="easyui-combobox" data-options="width:120,height:20, panelHeight:'auto' ">
                        </select>
                    </div>
                    <div style="clear: both">
                    </div>
                    <div style="float: left; margin-left: 0px;margin-top:5px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            排产开始日期</div>
                        <input id="txtStartDate" type="text" class="easyui-datetimebox" style="height: 20px;
                            width: 148px" />
                    </div>
                    <div style="float: left; margin-left: 10px;margin-top:5px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            排产结束日期</div>
                        <input id="txtEndDate" type="text" class="easyui-datetimebox" style="height: 20px;
                            width: 148px" />
                    </div>
                </div>
                <div style="float: left; margin-left: 10px; width: 300px">
                    <div class="divLabel" style="margin-bottom: 5px">
                        加工人员</div>
                    <table id="gdMakeEmployee" class="easyui-datagrid" style="width: 100%; height: 150px"
                        data-options="rownumbers:true,pagination:false,striped:true,checkOnSelect:true,selectOnCheck:true,singleSelect:false,pageNumber:1,pageSize:5,pageList:[5,10,20]">
                    </table>
                </div>
                <div style="clear: both">
                </div>
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="按钮区域" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <a href="#" id="btnSaveChange" class="easyui-linkbutton" data-options="" style="margin-top: 0px;">
                保存调整</a>
        </div>
    </div>
    <div id="statusMessage" style="font-size: 14px; height: 40px">
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
    创建人：zhangrj
    日期：2022-07-06
    描述：排产反馈页面js
    */
    var page = {
        url: getRootPath() + "/Ashx/ApsHandler/ApsPlanConfirmHandler.ashx", //后台处理url,
        ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ApsLimitedCapacityHandler.ashx",
        //设备分页参数
        pageTotal: 0,
        pageSize: 10,
        pageNumber: 1,
        init: function () {
            page.bind();
            page.initPage();
        },
        //绑定事件
        bind: function () {
            customizedEasyuiPagination('pp'); //定制化分页
            //设备列表加载
            $("#gdApsPlanInfo").datagrid({
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pageTotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'MFGORDERNAME', title: '订单号', width: 150 },
                 { field: 'CONTAINERNAME', title: '批次', width: 150 },
                 { field: 'DESCRIPTION', title: '零件名称', width: 150 },
                 { field: 'QTY', title: '在制数', width: 60 },
                 { field: 'WORKFLOWNAME', title: '工艺', width: 150 },
                 { field: 'WORKFLOWSTEPNAME', title: '排产工序', width: 150 },
                 { field: 'CONTAINERTYPENAME', title: '流水卡类型', width: 100 },
                 { field: 'APSTYPENAME', title: '排产策略', width: 80 },
                 { field: 'STARTTIME', title: '排产开始时间', width: 100,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 },
                 { field: 'ENDTIME', title: '排产结束时间', width: 100,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 },
                  { field: 'FEEDBACKDATE', title: '反馈开始时间', width: 100,
                      formatter: function (value, row, index) {
                          if (!isNullOrWhiteSpaceStr(value)) {
                              return dayjs(value).format('YYYY-MM-DD');
                          }
                      }
                  },
                   { field: 'FULLNAME', title: '确认人', width: 80 },
                  { field: 'CONFIRMDATE', title: '确认时间', width: 100,
                      formatter: function (value, row, index) {
                          if (!isNullOrWhiteSpaceStr(value)) {
                              return dayjs(value).format('YYYY-MM-DD');
                          }
                      }
                  },
                    { field: 'MAKEEMPCOUNTS', title: '加工人员', width: 80 }
                ]],
                 onSelect: function (index, rowData) {
                    page.clearPage(false, false, true); //清除数据
                    page.loadStepDetail(rowData);
                },
            });
            $("#gdMakeEmployee").datagrid({
                onLoadSuccess: function (data) {
                    for (var i = 0; i < data.rows.length; i++) {
                        if (data.rows[i].checked == true) {
                            $(this).datagrid('checkRow', i);
                        }
                    }
                },
                columns: [[
                    { field: 'ck', title: '选择', checkbox: true },
                    { field: 'EMPLOYEENAME', title: '员工号', width: 100 },
                    { field: 'FULLNAME', title: '姓名', width: 100 },
                    { field: 'EMPLOYEEID', title: 'EMPLOYEEID', hidden: true }
                ]]
            });
            //设备列表分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.search();
                }
            });
            //查询信息
            $("#btnSearch").on("click", function () {
                page.pageNumber = 1;
                page.search();
            });
            //重置查询
            $("#btnReset").on("click", function () {
                page.clearPage(true, true, true);
            });
             //调整
            $('#btnSaveChange').on("click", function () {
                page.LimitedCapacityChange();
            });
        },
        //初始化页面
        initPage: function () {
          $(document).ready(function () {
            $("#ddlWorkcenter").combobox({
                panelHeight: 'auto',
                valueField: 'WORKCENTERID',
                textField: 'WORKCENTERNAME',
                url: page.ajaxUrl + "?action=getWorkcenter",
                onSelect: function (record) {
                    page.loadTeam(record.WORKCENTERID);
                }
            });
            $("#ddlTeam").combobox({
                panelHeight: 'auto',
                valueField: 'TEAMID',
                textField: 'TEAMNAME'
            });

            $("#ddlResource").combobox({
                panelHeight: 'auto',
                valueField: 'RESOURCEID',
                textField: 'RESNAME',
                onSelect: function (record) {
                    $.ajax({
                        type: "Get",
                        url: page.ajaxUrl + "?action=getResEmployee&resourceId=" + record.RESOURCEID,
                        cashe: false,
                        async: false, //同步
                        beforeSend: function () {

                        },
                        success: function (data) {
                            var result = JSON.parse(data);
                            $("#gdMakeEmployee").datagrid('loadData', { total: result.length, rows: result });
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest.responseText);
                        }
                    });
                },
                onLoadSuccess: function () {

                }
            });
            });
        },
        loadTeam: function (workcenterId) {
            if (isNullOrWhiteSpaceStr(workcenterId)) {
                return;
            }
            //console.log('select workcenter'); 
            $("#ddlTeam").combobox('clear');
            $.ajax({
                type: "Get",
                url: page.ajaxUrl + "?action=getTeam&workcenterId=" + workcenterId,
                cashe: false,
                async: false, //同步
                beforeSend: function () {

                },
                success: function (data) {
                    $("#ddlTeam").combobox('loadData', JSON.parse(data))
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.responseText);
                }
            });
            //$("#ddlTeam").combobox( 'reload', page.ajaxUrl+"?action=getTeam&workcenterId="+workcenterId );
        },
        loadResource: function (specid) {
            if (isNullOrWhiteSpaceStr(specid)) {
                return;
            }
            //console.log('select workcenter'); 
            $("#ddlResource").combobox('clear');

            $.ajax({
                type: "Get",
                url: page.ajaxUrl + "?action=getResourceBySpec&specId=" + specid,
                cashe: false,
                async: false, //同步
                beforeSend: function () {

                },
                success: function (data) {
                    $("#ddlResource").combobox('loadData', JSON.parse(data))
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        //查询
        search: function () {
          page.clearPage(false, true, true);
            var params = [{
                mfgOrderName: $("#txtOrderNum").textbox("getValue"), //订单号
                containerName: $("#txtContainerNum").textbox("getValue"), //批次号
                productName: $("#txtProductNum").textbox("getValue"), //件号
                startTime: $("#txtPlanStartTime").textbox("getValue"), //开始时间
                endTime: $("#txtPlanEndTime").textbox("getValue") //结束时间
            }];
            var formData = {
                pageSize: page.pageSize,
                pageNumber: page.pageNumber,
                type: page.pageType, //功能参数
                action: "GetApsFeedBackByPage",
                params: JSON.stringify(params)
            };
            page.post(page.url, formData, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                page.pageTotal = res.RowCount;
                $("#gdApsPlanInfo").datagrid('loadData', { total: res.RowCount, rows: res.DBTable });
            });
        },
        //加载填写信息
        loadStepDetail: function (row) {
            //$('#ddlWorkcenter').combobox('select', row.WORKCENTERID);

            $('#ddlWorkcenter').combobox('select', row.WORKCENTERID);
            $("#ddlTeam").combobox('select', row.TEAMID);
            //加载设备
            page.loadResource(row.SPECID);
            $("#ddlResource").combobox('select', row.RESOURCEID);
            //加载人员,已排产的人员排前面
            var data = $("#gdMakeEmployee").datagrid('getData').rows;
            var emps = row.EMPLOYEEIDS;
            var newData = [];
            var newData2 = [];
            data.forEach(function (e) {
                if (emps.indexOf(e.EMPLOYEEID) != -1) {
                    e.checked = true;
                    newData.push(e);
                } else {
                    newData2.push(e);
                }
            });
            mergerNoRepeat(newData, newData2); //将newData2合并到newData中去 

            $("#gdMakeEmployee").datagrid('loadData', { total: data.length, rows: newData })
            //加载开始结束时间
            //console.log(row);
            $('#txtStartDate').datetimebox('setValue', row.STARTTIME);
            $('#txtEndDate').datetimebox('setValue', row.ENDTIME);
        },
         //调整
        LimitedCapacityChange: function () {
            var activeRow = $("#gdApsPlanInfo").datagrid('getSelected');
            if (activeRow == null) {
                displayMessage("请选择批次", false);
                return;
            }
            var containers = [];
            var container = {
                containerid: activeRow.CONTAINERID,
                workflowid: activeRow.WORKFLOWID
            }
            if (activeRow.APSTYPE == "1") {
                container.startTime = $("#txtEndDate").datebox('getValue');
                container.endTime = activeRow.ENDTIME;
            } else if (activeRow.APSTYPE == "2") {
                container.endTime = $("#txtStartDate").datebox('getValue');
                container.startTime = activeRow.STARTTIME;
            } else if (activeRow.APSTYPE == "3") {
                container.startTime = activeRow.STARTTIME;
                container.endTime = activeRow.ENDTIME;
            }
            containers.push(container);

            var selectEmp = $("#gdMakeEmployee").datagrid('getChecked');

            if (parseInt(activeRow.MAKEEMPCOUNTS) != selectEmp.length) {
                displayMessage("所选工序作业人数和指定人数不一致", false);
                return;
            }

            var employeeIds = "";
            selectEmp.forEach(function (item) {
                employeeIds += item.EMPLOYEEID + ","
            });
            employeeIds = employeeIds.trimEnd(",");

            var postData = {
                action: "apsLmCalculateChange",
                apstype: activeRow.APSTYPE,
                apsplanDetailId: activeRow.APSPLANDETAILID,
                startTime: $("#txtStartDate").datebox('getValue'),
                endTime: $("#txtEndDate").datebox('getValue'),
                workcenterId: $("#ddlWorkcenter").combobox('getValue'),
                TeamId: $("#ddlTeam").combobox('getValue'),
                resourceId: activeRow.RESOURCEID,
                employeeIds: employeeIds,
                sequence: activeRow.SEQUENCE,
                containers: JSON.stringify(containers)
            }

            //startTime: $("#txtStartDate").datebox('getValue'), //txtStartDate
            //endTime: $("#txtEndDate").datebox('getValue'),

            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: postData,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    //console.log(data);
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        page.search();
                        displayMessage("调整成功", true);
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        //清空页面（查询，结果，填写）
        clearPage: function (query, result, fill) {
            clearMessage();
            if (query) {
                $("#txtOrderNum").textbox("setValue", ""); //订单号
                $("#txtContainerNum").textbox("setValue", ""); //批次号
                $("#txtProductNum").textbox("setValue", ""); //件号
                $("#txtPlanStartTime").textbox("setValue", ""); //排产开始时间
                $("#txtPlanEndTime").textbox("setValue", ""); //排产结束时间
            }
            if (result) {
                clearEasyuiDataGrid("gdApsPlanInfo");
            }
            if (fill) {
                $("#ddlWorkcenter").combobox('select', '');
                $("#ddlTeam").combobox('select', '');
                $("#ddlResource").combobox('loadData', []);
                $('#txtStartDate').datetimebox('clear');
                $('#txtEndDate').datetimebox('clear');
                clearEasyuiDataGrid("gdMakeEmployee", 1);
            }
        },
        //post数据（路径，参数，是否异步，成功返回方法）
        post: function (url, param, async, callback) {
            $.ajax({
                type: "Post",
                url: url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    $("body").find(".easyui-linkbutton").each(function () {
                        $(this).linkbutton('enable');
                    });
                }
            });
        }
    }
    page.init();
</script>
